﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System.Threading.Tasks;
using WMS.Seven.ProductSaleDetils;
using WMS.Seven.ProductSaleDetils.Dto;

namespace WMS.Seven.Web
{
    public class ProductSaleDetilsController : Controller
    {
        private readonly ProductSaleDetilsAppService _productSaleDetilsAppService;

        public ProductSaleDetilsController(ProductSaleDetilsAppService productSaleDetilsAppService)
        {
            _productSaleDetilsAppService = productSaleDetilsAppService;
        }


        public async Task<IActionResult> GetSelecProduct()
        {
            var result = await _productSaleDetilsAppService.SelectProduct();
            return Ok(result);
        }

        [HttpGet]
        public async Task<IActionResult> AddproductSalects(ProductSalesDto input)
        {
            var index = _productSaleDetilsAppService.AddProductSaleis(input);
            return Json(index);
        }

        [HttpGet]
        public async Task<IActionResult> SelectProducSaleDetils(string SalesOrderCode, string ProductCode, string ProductName, int pageIndex, int pageSize)
        {
            var result = await _productSaleDetilsAppService.SelectFormProductSale(SalesOrderCode, ProductCode, ProductName, pageIndex, pageSize);
            return Ok(JsonConvert.SerializeObject(new PageDto<PSDelitDto> { code = "", data = result, msg = "", count = result.Count }));
        }

        [HttpGet]
        public async Task<IActionResult> DeleteProductSaleDetils(string SalesOrderCode)
        {
            var result = await _productSaleDetilsAppService.DeleteProduSaleDetils(SalesOrderCode);
            return Ok(result);
        }

        [HttpGet]
        public async Task<IActionResult> SelectProductSaleDetilsById(string SalesOrderCode)
        {
            var result = await _productSaleDetilsAppService.FillSaleDetailsAsync(SalesOrderCode);
            return Ok(result);
        }


        [HttpGet]
        public async Task<IActionResult> SelectProductById(string ProductCode)
        {
            var result = await _productSaleDetilsAppService.GetProductIdsBySaleIdAsync(ProductCode);
            return Ok(result);
        }



        public IActionResult SaleDetils()
        {
            return View();
        }

        public IActionResult AddDetils()
        {
            return View();
        }


        public IActionResult UpdateProductSelectDetils()
        {
            return View();
        }


        
    }
}
